
*****************************************************************************
*******Tables 1,4: Summary Stats Using "Sum" command***********************
*****************************************************************************


***********************************************************
********Table 2: Market Shares*****************************
***********************************************************
clear
set mem 500m
set matsize 800
set more off
cd "P:\NPD\Data Update"
use npdit_update.dta, clear
bysort brand modela: egen totunits = total(units)
gen unit_share = units/totunits
sort brand modela time
by brand modela: gen units_cdf = sum(unit_share)
gen leftcens = 0
replace leftcens = 1 if position == 1 & time == 501
bysort brand modela: egen leftcens_temp = max(leftcens)
drop if leftcens_temp == 1
keep if totunits > 1000

keep if brand == "Apple"| brand == "Compaq" | brand == "Emachines" | brand == "Hewlett Packard" | brand == "Sony" | brand == "Toshiba" | brand == "Acer" | brand == "Gateway"
gen PC = 0
replace PC = 1 if brand ~= "Apple"
egen totunits_all = total(units)
bysort brand: egen totunits_brand = total(units) 
*Repeat for desktops and notebooks*

*************************************************
*******Table 3: Adoption of New Models***********
*************************************************

clear
set mem 500m
set matsize 800
set more off
cd "P:\NPD\Data Update"
use npdit_update.dta, clear
bysort brand modela: egen totunits = total(units)
gen unit_share = units/totunits
sort brand modela time
by brand modela: gen units_cdf = sum(unit_share)
gen leftcens = 0
replace leftcens = 1 if position == 1 & time == 501
bysort brand modela: egen leftcens_temp = max(leftcens)
drop if leftcens_temp == 1
keep if totunits > 1000
*drop if count == 1

sort brand modela time
*drop if units_cdf > .90
*drop if units_cdf < .01
by brand modela: gen newpos = _n
by brand modela: gen newcount = _N
cd "P:\NPD\Data Update"

keep if brand == "Apple"| brand == "Compaq" | brand == "Emachines" | brand == "Hewlett Packard" | brand == "Sony" | brand == "Toshiba" | brand == "Acer" | brand == "Gateway"
gen PC = 0
replace PC = 1 if brand ~= "Apple"
 

replace brand = "HP" if brand == "Hewlett Packard"
global brand_name "Apple Compaq HP Sony Toshiba Acer Gateway Emachines"

foreach i of global brand_name {
bysort time: egen nummodsall_`i' = total(dum) if brand == "`i'" & newpos == 1
bysort time: egen nummodsdesk_`i' = total(dum) if brand == "`i'" & newpos == 1 & subcat == "Desktop Computers"
*bysort time: egen nummodsnote_`i' = total(dum) if brand == "`i'" & newpos == 1 & subcat == "Notebook Computers"
bysort time: egen nummodsnote_`i' = total(dum) if brand == "`i'" & newpos == 1 & subcat == "Notebook Computers" & display >14.9 & display < 16

}

collapse (mean) nummods*, by(time)

foreach i of global brand_name {
replace nummodsall_`i' = 0 if nummodsall_`i' == .
gen noadopt_`i' = 0
replace noadopt_`i' = 1 if nummodsall_`i' == 0 & time > 502
gen lastadopt_`i' = time 
replace lastadopt_`i' = lastadopt_`i'[_n-1] if noadopt_`i' == 1 & time > 502
gen adoptlag_`i' = time - lastadopt_`i' if time > 502

replace nummodsdesk_`i' = 0 if nummodsdesk_`i' == .
gen noadoptd_`i' = 0
replace noadoptd_`i' = 1 if nummodsdesk_`i' == 0 & time > 502
gen lastadoptd_`i' = time 
replace lastadoptd_`i' = lastadoptd_`i'[_n-1] if noadoptd_`i' == 1 & time > 502
gen adoptlagd_`i' = time - lastadoptd_`i' if time > 502

replace nummodsnote_`i' = 0 if nummodsnote_`i' == .
gen noadoptn_`i' = 0
replace noadoptn_`i' = 1 if nummodsnote_`i' == 0 & time > 502
gen lastadoptn_`i' = time 
replace lastadoptn_`i' = lastadoptn_`i'[_n-1] if noadoptn_`i' == 1 & time > 502
gen adoptlagn_`i' = time - lastadoptn_`i' if time > 502
}

save number_of_models.dta, replace

replace noadopt_Acer = . if time < 537
replace noadoptd_Acer = . if time < 537
replace noadoptn_Acer = . if time < 537
replace adoptlag_Acer = . if time < 537
replace adoptlagd_Acer = . if time < 537
replace adoptlagn_Acer = . if time < 537

replace noadopt_Gateway = . if time < 537
replace noadoptd_Gateway = . if time < 537
replace noadoptn_Gateway = . if time < 537
replace adoptlag_Gateway = . if time < 537
replace adoptlagd_Gateway = . if time < 537
replace adoptlagn_Gateway = . if time < 537

foreach i of global brand_name {
egen meanzero_`i' = mean(noadopt_`i') 
egen meanzerod_`i' = mean(noadoptd_`i')
egen meanzeron_`i' = mean(noadoptn_`i')
egen maxlag_`i' = max(adoptlag_`i')
egen maxlagd_`i'= max(adoptlagd_`i')
egen maxlagn_`i' = max(adoptlagn_`i')
}

keep mean* max*
keep if _n == 1
*outsheet using "C:\Documents and Settings\odaxs1\My Documents\NPD\Data Update\Sim Numbers\num_mods.csv", comma replace

*clear
